//
//  ZZViewController.m
//  ZZNetWorker
//
//  Created by zenglizhi on 01/30/2024.
//  Copyright (c) 2024 zenglizhi. All rights reserved.
//

#import "ZZViewController.h"
#import "ZZNormalViewController.h"
#import "WCNetDemoViewController.h"
#import "ZZListDemoViewController.h"
#import "XHMBTextStreamViewController.h"

@interface ZZViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataArray;
@end

@implementation ZZViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = @"首页";
    
    self.dataArray = @[@"普通示例",@"图片上传",@"挖错网请求示例",@"新华妙笔流式请求",@"列表data是数组"];
    
    [self.view addSubview:self.tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *text = [self.dataArray objectAtIndex:indexPath.row];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text = text;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *text = [self.dataArray objectAtIndex:indexPath.row];
    
    if ([text isEqualToString:@"普通示例"]) {
        ZZNormalViewController *vc = [[ZZNormalViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([text isEqualToString:@"图片上传"]) {
        
    }else if ([text isEqualToString:@"挖错网请求示例"]) {
        WCNetDemoViewController *vc = [[WCNetDemoViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([text isEqualToString:@"新华妙笔流式请求"]) {
        XHMBTextStreamViewController *vc = [[XHMBTextStreamViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([text isEqualToString:@"列表data是数组"]) {
        ZZListDemoViewController *vc = [[ZZListDemoViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return _tableView;
}

@end
